package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.example.project.entity.UserPosition;

/**
 * 用户与岗位关联表 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface UserPositionMapper{
	
	/**
	 * 通过用户ID删除用户和岗位关联
	 * 
	 * @param userId 用户ID
	 * @return 结果
	 */
	@Delete("delete from t_user_position where user_id=#{userId}")
	public int deleteUserPostByUserId(Long userId);

	/**
	 * 通过岗位ID查询岗位使用数量
	 * 
	 * @param postId 岗位ID
	 * @return 结果
	 */
	@Select("select count(1) from t_user_position where post_id=#{postId}")
	public int countUserPostById(Long postId);

	/**
	 * 批量删除用户和岗位关联
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Delete("<script>delete from t_user_position where user_id in <foreach collection='array' item='userId' open='(' separator=',' close=')'>#{userId}</foreach></script>")
	public int deleteUserPost(Long[] ids);

	/**
	 * 批量新增用户岗位信息
	 * 
	 * @param userPostList 用户岗位列表
	 * @return 结果
	 */
	@Insert("<script>insert into t_user_position(user_id, post_id) values <foreach item='item' index='index' collection='list' separator=','>(#{item.userId},#{item.postId})</foreach></script>")
	public int batchUserPost(List<UserPosition> userPostList);
}
